package typejump.commands;

import typejump.TypeJump;
import typejump.engine.GameEngine;


public class DevGridSnap implements TextCommand {

	@Override
	public boolean matches(String command) {
		return command.matches("dev grid snap( .*)?");
	}

	@Override
	public void act(String command) {
		TypeJump tj = TypeJump.getInst();
		command = command.substring("dev grid snap".length()).trim();
		
		if (command.length() == 0) {
			boolean on = tj.toggleGridSnap();
			GameEngine.addTextEffect("GRID SNAP " + (on?"ENABLED":"DISABLED"), "dev");
		} else if (command.equals("on")) {
			tj.enableGridSnap();
			GameEngine.addTextEffect("GRID SNAP ENABLED", "dev");
		} else if (command.equals("off")) {
			tj.disableGridSnap();
			GameEngine.addTextEffect("GRID SNAP DISABLED", "dev");
		} else if (command.matches("\\d+")) {
			int i = Integer.parseInt(command);
			if (i > 0) {
				tj.setGridSnapAmount(i);
				tj.enableGridSnap();
				GameEngine.addTextEffect("GRID SNAP = " + i, "dev");
			}
		}
	}

}
